<template>
  <div>
    <AppSearch></AppSearch>
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="blue">
      <van-swipe-item v-for="item in banner" :key="item.id">
        <img :src="item.image_url" alt="" style="width: 100%" />
      </van-swipe-item>
    </van-swipe>
    <!-- 5个通道 -->
    <van-grid :column-num="5">
      <van-grid-item
        v-for="item in channel"
        :key="item.id"
        :icon="item.icon_url"
        :text="item.name"
      />
    </van-grid>
    <!-- 品牌制造商直供 -->
    <div class="brand">
      <van-panel title="品牌制造商直供">
        <van-grid column-num="2" gutter="3px">
          <van-grid-item v-for="item in brandList" :key="item.id">
            <img
              :src="item.pic_url"
              style="width: 100%; font-size: 0px"
              alt=""
            />
            <div style="postion: absolute; z-index: 999">{{ item.name }}</div>
            <div style="postion: absolute; z-index: 999">
              {{ item.floor_price | RMB }}
            </div>
          </van-grid-item>
        </van-grid>
      </van-panel>
    </div>
    <!-- 新品首发 -->
    <div class="news">
      <div class="news_title">周一周四 · 新品首发</div>
      <div class="list_box">
        <div class="news_list" v-for="item in newGoodsList" :key="item.id" @click="$router.push({name:'Productdetail',params:{id:item.id}})">
          <div>
            <img :src="item.list_pic_url" alt="" />
          </div>
          <div>
            <h4>{{ item.name }}</h4>
            <h4>￥ {{ item.retail_price }} 元</h4>
          </div>
        </div>
      </div>
    </div>
    <!-- 人气推荐 -->
    <div class="hot">
      <div class="hot_title">人气推荐</div>
      <div class="hot_list">
        <van-card
          v-for="item in hotGoodsList"
          :key="item.id"
          :price="item.retail_price"
          :desc="item.goods_brief"
          :title="item.name"
          :thumb="item.list_pic_url"
        >
        </van-card>
      </div>
    </div>
    <!-- 居家,餐厨... -->
    <div class="category" v-for="item in categoryList" :key="item.id">
      <div class="title">{{ item.name }}</div>
      <div class="content">
        <div class="item" v-for="list in item.goodsList" :key="list.id">
          <div>
            <img :src="list.list_pic_url" alt="" />
          </div>
          <h4>{{ list.name }}</h4>
          <h4>￥ {{ list.retail_price }} 元</h4>
        </div>
      </div>
    </div>
    <!-- logo -->
    <div class="logo"></div>
  </div>
</template>

<script>
import { Index } from "@/api/home.js";
import AppSearch from "../components/AppSearch.vue";
export default {
  async beforeCreate() {
    let res = await Index();
    // console.log(res);
    let {
      data: {
        data: {
          banner,
          channel,
          brandList,
          newGoodsList,
          hotGoodsList,
          categoryList,
        },
      },
    } = res;
    this.banner = banner;
    this.channel = channel;
    this.brandList = brandList;
    this.newGoodsList = newGoodsList;
    this.hotGoodsList = hotGoodsList;
    this.categoryList = categoryList;
    // console.log(categoryList);
  },
  data() {
    return {
      banner: [],
      channel: [],
      brandList: [],
      newGoodsList: [],
      hotGoodsList: [],
      categoryList: [],
    };
  },
  components:{
    AppSearch,
  }
};
</script>

<style lang="less" scoped>
.brand {
  .van-cell__title {
    font-size: 16px;
    text-align: center;
  }
  .van-grid-item {
    position: relative;
    height: 120px;
    img {
      position: absolute;
    }
  }
  .van-grid {
    font-size: 14px;
  }
}
.news {
  width: 100%;
  .news_title {
    font-size: 16px;
    text-align: center;
    line-height: 50px;
  }
  .list_box {
    display: flex;
    flex-wrap: wrap;
    .news_list {
      width: 50%;
      box-sizing: border-box;
      font-size: 16px;
      text-align: center;
      img {
        width: 100%;
      }
    }
  }
}
.hot {
  .hot_title {
    font-size: 16px;
    text-align: center;
    line-height: 50px;
  }
  .van-card {
    font-size: 14px;
  }
  .van-card__title {
    margin-bottom: 12px;
  }
}
.brand_title {
  text-align: center;
  line-height: 50px;
  height: 50px;
  width: 100%;
  font-size: 16px;
}
.category {
  .title {
    text-align: center;
    font-size: 16px;
    height: 30px;
    line-height: 30px;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .content {
    display: flex;
    flex-wrap: wrap;
    padding: 5px;
    .item {
      width: 50%;
      box-sizing: border-box;
      img {
        width: 100%;
      }
      h4 {
        font-size: 16px;
        text-align: center;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }
    }
  }
}

.logo {
  height: 50px;
  width: 100%;
  background-color: #f4f4f4;
}
</style>